package homework;

public class polymorphicDemo {
    public static void main(String[] args) {


       /* Master master=new Master();
        Dog dog=new Dog("小黑",2,"黑");
        Chick chick=new Chick("小白",3,"白");
        Fish fish=new Fish("小金",2,"金");
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);*/

        Animal[]animals=new Animal[3];
        animals[0]=new Dog("小黑",2,"黑");
        animals[1]=new Chick("小白",3,"白");
        animals[2]=new Fish("小金",2,"金");
        for(int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog1=(Dog)animals[i];
                dog1.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Fish){
                Fish fish=(Fish) animals[i];
                fish.swim();
            }
            if (animals[i] instanceof Swim){
                Swim swim=(Swim) animals[i];
                swim.swim();
            }
        }







    }

















       /* Master master=new Master();
        Dog dog=new Dog("小黑",2,"黑");
        Chick chick=new Chick("小白",2,"白");
        Fish fish=new Fish("小金",2,"金");
        master.feed(Dog);
        master.feed(Chick);
        master.feed(Fish);*/

    /*public static void main(String[] args) {


        Animal[] animals=new Animal[3];
        animals[0]=new Dog("小黑",2,"黑");
        animals[1]=new Chick("小白",3,"白");
        animals[2]=new Fish("小金",1,"金");
        for(int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if(animals[i] instanceof Dog){
                Dog dog=(Dog)animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if(animals[i] instanceof Swim){
                Swim swim=(Swim) animals[i];
                swim.swim();
            }
        }
    }*/
}
